<?php

namespace app\common\model;

use think\Db;
use think\Model;


/**
 * 会员模型
 */
class Channel extends Model
{
    /**
     * 自动完成
     * @var array
     */
    //protected $auto = ['name', 'ip'];
    protected $insert = ['status' => 1];
    protected $update = [];
    /**
     * 得到左边菜单栏的数据
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getMenu()
    {
        $firstCate = Db('channel')->where('status', 1)->where('pid', 0)->order('sort asc')->select();
        foreach ($firstCate as &$v) {
            $where = [
                'status' => 1,
                'pid' => $v['id'],
            ];
            $second = Db('channel')->where($where)->order('sort asc')->select();
            foreach($second as &$vv){
                $vv['url'] = url($vv['url']);
            }
            if ($second) {
                $v['url'] = '#';
                $v['_child'] = $second;
            }else{
                $v['url'] = url($v['url']);
                $v['_child'] = [];
            }
        }
        return $firstCate ;
    }
}
